
var baseEgoCap:int=100;
var egoModifier=0;
var currentEgo=100;
var baseEgoRegen:int=10;
var startingSize=100;

var playerName:String;
var teamNum:int;
var slots:Array=new Array();
var slotSpeeds:Array=new Array();

var playerStats:Array=[0,0,0,0,0,0];
var playerStatBuffs:Array=[0,0,0,0,0,0];
var playerStatDebuffs:Array=[0,0,0,0,0,0];
var playerStatPassives:Array=[0,0,0,0,0,0];
enum statEnum{EgoRegen,Ego,Speed,Attack,Building,StartingSize};
enum buffEnum{EgoRegen,Building,Attack};

var buffTimers:Array=[0,0,0,0,0,0];
var debuffTimers:Array=[0,0,0,0,0,0];

//Slots indexes 0-4 are Active and 5-7 are Passive
enum slotEnum{PlayerNum,PlayerSlot,Name,EgoCost,Effect,Power,Duration,Type};

function GetStartingSizeBonus(){
	return this.startingSize;
}
	

function UpdateBuffs ()
{
	var i;
	for(i=0;i<6;i++)
	{
		if(buffTimers[i]!=0) 
		{
			buffTimers[i]=buffTimers[i]-1;
		}
		else
		{
			playerStatBuffs[i]=0;
		}
		if(debuffTimers[i]!=0)
		{		
			debuffTimers[i]=debuffTimers[i]-1;
		}
		else
		{
			playerStatDebuffs[i]=0;
		}
	}
}
		
function UpdateStats()
{
	var i;
	for(i=0;i<6;i++)
	{
		if(i==0)
		{
			playerStats[i]=baseEgoRegen+playerStatBuffs[i]+playerStatPassives[i]+playerStatDebuffs[i];
		}
		else if(i==1)
		{
			playerStats[i]=baseEgoCap+playerStatBuffs[i]+playerStatPassives[i]+playerStatDebuffs[i];
		}
		else
		{
			playerStats[i]=playerStatBuffs[i]+playerStatPassives[i]+playerStatDebuffs[i];
		}
	}
}

function ImportSlots()
{
	var i;
	for(i=1;i<9;i++)
	{
		//Debug.Log("Preparing to import slot "+ i + "for player " +this.teamNum);
		curSlot=this.gameObject.GetComponent("HandHandler").GetSlot(this.teamNum,i);
		//Debug.Log(curSlot[8]);
		this.slotSpeeds.Add(curSlot[8]);
		this.slots.Add(curSlot);
	}
	//print("Import Slots Complete");
}

function SetupPassive()
{
	var i;
	for(i=5;i<8;i++)
	{
		if (this.slots[i][2] != "Empty")
		{
			var passiveType= this.slots[i][4];
			var passivePower=this.slots[i][5];
			//Debug.Log(passiveType + " " + passivePower);
			
			
			if (passiveType== "Ego Regen Buff")
			{
				this.playerStatPassives[statEnum.EgoRegen]=
					this.playerStatPassives[statEnum.EgoRegen]+passivePower;
			}
			else if (passiveType== "Ego Buff")
			{
				this.playerStatPassives[statEnum.Ego]=
					this.playerStatPassives[statEnum.Ego]+passivePower;
			}
			else if (passiveType== "Speed Buff")
			{
				this.playerStatPassives[statEnum.Speed]=
					this.playerStatPassives[statEnum.Speed]+passivePower;
			}
			else if (passiveType== "Attack Buff")
			{
				this.playerStatPassives[statEnum.Attack]=
					this.playerStatPassives[statEnum.Attack]+passivePower;
			}
			else if (passiveType== "Building Buff")
			{
				this.playerStatPassives[statEnum.Building]=
					this.playerStatPassives[statEnum.Building]+passivePower;
			}
			else if (passiveType== "Starting Size Buff")
			{
				this.playerStatPassives[statEnum.StartingSize]=
					this.playerStatPassives[statEnum.StartingSize]+passivePower;
			}
		}
	}
}

function DecreaseEgo(amount:int)
{
	this.currentEgo=this.currentEgo-amount;
	if (this.currentEgo<0) this.currentEgo=0;
}

function AddEgo(amount:int)
{
	this.currentEgo=this.currentEgo+amount;
	if (this.currentEgo>this.baseEgoCap) this.currentEgo=this.baseEgoCap;
}

function EgoRegen(){
	egoReg=this.baseEgoRegen;
	this.AddEgo(egoReg);
}

function CastBuff(type:String,power:int,duration:int)
{
			if (type== "Ego Regen Buff")
			{
				this.playerStatBuffs[statEnum.EgoRegen]= power;
				this.buffTimers[statEnum.EgoRegen]=duration;
			}
			else if (type== "Ego Buff")
			{
				this.playerStatBuffs[statEnum.Ego]= power;
				this.buffTimers[statEnum.EgoRegen]=duration;
			}
			else if (type== "Speed Buff")
			{
				this.playerStatBuffs[statEnum.Speed]= power;
				this.buffTimers[statEnum.EgoRegen]=duration;
			}
			else if (type== "Attack Buff")
			{
				this.playerStatBuffs[statEnum.Attack]= power;
				this.buffTimers[statEnum.EgoRegen]=duration;
			}
			else if (type== "Building Buff")
			{
				this.playerStatBuffs[statEnum.Building]= power;
				this.buffTimers[statEnum.EgoRegen]=duration;
			}
			else if (type== "Starting Size Buff")
			{
				this.playerStatBuffs[statEnum.StartingSize]= power;
				this.buffTimers[statEnum.EgoRegen]=duration;
			}
}

function CastDebuff(type:String,power:int,duration:int)
{
			if (type== "Ego Regen Buff")
			{
				this.playerStatDebuffs[statEnum.EgoRegen]= power;
				this.debuffTimers[statEnum.EgoRegen]=duration;
			}
			else if (type== "Ego Buff")
			{
				this.playerStatDebuffs[statEnum.Ego]= power;
				this.debuffTimers[statEnum.EgoRegen]=duration;
			}
			else if (type== "Speed Buff")
			{
				this.playerStatDebuffs[statEnum.Speed]= power;
				this.debuffTimers[statEnum.EgoRegen]=duration;
			}
			else if (type== "Attack Buff")
			{
				this.playerStatBuffs[statEnum.Attack]= power;
				this.debuffTimers[statEnum.EgoRegen]=duration;
			}
			else if (type== "Building Buff")
			{
				this.playerStatDebuffs[statEnum.Building]= power;
				this.debuffTimers[statEnum.EgoRegen]=duration;
			}
			else if (type== "Starting Size Buff")
			{
				this.playerStatDebuffs[statEnum.StartingSize]= power;
				this.debuffTimers[statEnum.EgoRegen]=duration;
			}
}

function GetHandTypes()
{
	var result=new Array();
	var i;
	for(i=0;i<5;i++)
	{
		curSlot=slots[i];
		curSlotType=curSlot[7];
		result[i]=curSlotType;
	}
	return result;
}

	